﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace EWDTAssignment
{
    public partial class ProductCatalog : System.Web.UI.Page
    {

   

        protected void Page_Load(object sender, EventArgs e)
        {
       // Session["accountID"] = 1;
            if (!IsPostBack)
            {
                //Session["accountID"] = "1";

               
                if (Request.QueryString["category"] != null)
                {

            //    Session["category"] = Request.QueryString["category"].ToString();
                lblType.Text = Request.QueryString["category"].ToString();
                    lvProduct.DataSourceID = "dsProductByType";
                }
                else
                {
                    lvProduct.DataSourceID = "dsRetProduct";
                }
               
            }
          
        }
             
                       

        protected void lvProduct_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void dsRetProduct_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {

        }

      

        protected void lvProduct_ItemCommand1(object sender, ListViewCommandEventArgs e)
        {
     
            
            //Getting the selected item Product ID and store in the session
            Label pID = (Label)e.Item.FindControl("lblProdID");
            Session["ProductID"] = Convert.ToInt32(pID.Text);

            int aID = Convert.ToInt32(Session["accountID"].ToString());
            int prodID = Convert.ToInt32(Session["ProductID"].ToString());       
            int success = App_Code.DBManager.UpdateCartItem(1, aID, prodID);

           if (success == 1)
           {
          
               ClientScript.RegisterStartupScript(
          this.GetType(),
          Guid.NewGuid().ToString(),
          string.Format("alert('{0}')",
            "Item Added to Cart"),
            true);

                 
           }
           
            
           

            //If button Add To Cart clicked check if login and add to the acct Cart
        }

     
               

        protected void ProdName1Label_Click(object sender, EventArgs e)
        {
            
          
        }

        protected void imgBtnAddCart_Click(object sender, ImageClickEventArgs e)
        {
        }

        protected void DisplayAlert(string message)
        {
            ClientScript.RegisterStartupScript(
        this.GetType(),
        Guid.NewGuid().ToString(),
        string.Format("alert('{0}');window.location.href = 'index.aspx'",
          message.Replace("'", @"\'").Replace("\n", "\\n").Replace("\r", "\\r")),
          true);

           
        }
      
        
    }
}